package main

import (
	"common/ws_contact/reconnecting"
	"fmt"
	"log"
	"time"
)

func main() {
	ws := reconnecting.New("wss://estore.guanjieai.com:10007/hello", "sddd")
	ws.OnConnected(func() {
		log.Println("on connect")
		go func() {
			t := time.NewTicker(time.Second)
			for {
				select {
				case <-t.C:
					err := ws.SendTextMessage("hello")
					if err != nil {
						fmt.Println(err)
					}
				}
			}
		}()
	})
	ws.OnTextMessageSent(func(message string) {
		fmt.Println("send ", message)
	})
	ws.OnDisconnected(func(err error) {
		fmt.Println("OnDisconnected", err)
	})
	ws.OnConnectError(func(err error) {
		fmt.Println("OnConnectError", err)
	})

	go ws.Connect()
	select {}
}
